//
//  SAMySelfVC.m
//  saasRetail
//
//  Created by 黄志刚 on 2021/4/7.
//

#import "SAMySelfVC.h"
#import "SAMyAccountVC.h"
#import "SAPrintSettingsVC.h"
#import "SAMySelfCell.h"
#import "SASystemSettingsListAPI.h"
#import "SASystemSettingsCheckAPI.h"
#import "SADiscountSetVC.h"
#import "SAMemberSetVC.h"
#import "SAMemberIntegralVC.h"
#import "SAAboutUsVC.h"
#import "SAOpenPayVC.h"
#import "SAPaymentVC.h"
#import "SAPaperSetVC.h"


@interface SAMySelfVC ()<UITableViewDelegate,UITableViewDataSource,CAAnimationDelegate,HTTPAPIDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIView *headerView;
@property (nonatomic, strong) SAPrintSettingsVC *printSettingsVC;
@property (nonatomic, strong) NSMutableArray *dataMarr;

@property (nonatomic, strong) UIView *moreView;
@property (nonatomic, strong) UIImageView *imageV;
@property (nonatomic, strong) UILabel *noEraseLab;
@property (nonatomic, strong) UILabel *eraseAngleLab;
@property (nonatomic, strong) UILabel *erasePointsLab;
@property (nonatomic, strong) UIButton *noEraseBtn;
@property (nonatomic, strong) UIView *noEraseLine;
@property (nonatomic, strong) UIButton *eraseAngleBtn;
@property (nonatomic, strong) UIView *eraseAngleLine;
@property (nonatomic, strong) UIButton *erasePointsBtn;
@property (nonatomic, strong) UIView *erasePointsLine;
@property (nonatomic, strong) SASystemSettingsListAPI *systemSettingsListAPI;
@property (nonatomic, strong) SASystemSettingsCheckAPI *systemSettingsCheckAPI;

@property (nonatomic, strong) NSString *negativeInventory;
@property (nonatomic, strong) NSString *negativeSales;
@property (nonatomic, strong) NSString *mvoeZero;
@property (nonatomic, strong) NSString *calculate;

@property (nonatomic, strong) NSDictionary *mvoeZeroDic;
@property (nonatomic, strong) NSDictionary *negativeInventoryDic;
@property (nonatomic, strong) NSDictionary *negativeSalesDic;
@property (nonatomic, strong) NSDictionary *calculateDic;

@property (nonatomic, strong) NSDictionary *roundedDic;
@property (nonatomic, strong) NSString *rounded;
@property (nonatomic, strong) NSString *payment;//结算方式

@property (nonatomic, strong) NSString *individualDiscount;//散客是否享受折扣
@property (nonatomic, strong) NSDictionary *individualDiscountDic;

@property (nonatomic, strong) NSString *priorityPaymentMethod;//首付款方式
@property (nonatomic, strong) NSDictionary *priorityPaymentMethodDic;

@end

@implementation SAMySelfVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

#pragma mark - HTTPAPIDelegate
- (void)fetchData:(id)data fromServerSuccessedWithAPI:(HTTPAPI *)api {
    if (self.systemSettingsListAPI == api) {
        self.negativeInventory = data[@"data"][@"negative_stock_in"][@"value"];
        self.negativeInventoryDic = data[@"data"][@"negative_stock_in"];
        self.negativeSales = data[@"data"][@"negative_stock_out"][@"value"];
        self.negativeSalesDic = data[@"data"][@"negative_stock_out"];
        self.calculate = data[@"data"][@"calculate_commission"][@"value"];
        self.calculateDic = data[@"data"][@"calculate_commission"];
        self.individualDiscount = data[@"data"][@"individual_discount"][@"value"];
        self.individualDiscountDic = data[@"data"][@"individual_discount"];
        
        self.rounded = data[@"data"][@"rounding"][@"value"];
        self.roundedDic = data[@"data"][@"rounding"];
        
        self.priorityPaymentMethod = data[@"data"][@"priority_payment_method"][@"value"];
        self.priorityPaymentMethodDic = data[@"data"][@"priority_payment_method"];
        
        NSString *value = data[@"data"][@"settlement_method"][@"value"];
        NSArray *arr2 = [value componentsSeparatedByString:@","];
        if (arr2.count > 1) {
            if ([arr2[0] isEqualToString:@"0"]){
                self.payment = @"不结算";
            }else if ([arr2[0] isEqualToString:@"1"]) {
                self.payment = @"加收固定比例";
            }else if ([arr2[0] isEqualToString:@"2"]) {
                self.payment = @"加收固定金额";
            }else if ([arr2[0] isEqualToString:@"3"]) {
                self.payment = @"按固定金额核算";
            }
        }
        
        NSArray *arr = data[@"data"][@"special_cost"][@"childSettings"];
        for (NSDictionary *dic in arr) {
            NSString *settingsId = dic[@"templateId"];
            if ([settingsId isEqualToString:@"1"]) {
                self.mvoeZero = dic[@"value"];
                self.mvoeZeroDic = dic;
            }
        }
        [self.tableView reloadData];
    }else if (self.systemSettingsCheckAPI == api) {
        [self.systemSettingsListAPI sendRequestToServerWithActivityViewAndMask:GET];
    }
}

- (void)fetchDataFromServerFailedWithError:(NSError *)error API:(HTTPAPI *)api {
    
}


#pragma mark - UITableView Delegate & DataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataMarr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSArray *arr = self.dataMarr[section];
    return arr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    WeakSelf
    SAMySelfCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SAMySelfCell" forIndexPath:indexPath];
    NSArray *arr = self.dataMarr[indexPath.section];
    if ([SAValueManger shareInStance].userInfo.userType != 1) {
        if (indexPath.section == 0) {
            if (indexPath.row == 0) {
                [cell refreshCellWithTitle:arr[indexPath.row] info:self.mvoeZero AndType:1];
            }else if (indexPath.row == 1){
                [cell refreshCellWithTitle:arr[indexPath.row] info:self.rounded AndType:2];
            }else if (indexPath.row == 2){
                [cell refreshCellWithTitle:arr[indexPath.row] info:self.negativeInventory AndType:3];
            }else if (indexPath.row == 3){
                [cell refreshCellWithTitle:arr[indexPath.row] info:self.negativeSales AndType:4];
            }else if (indexPath.row == 4){
                [cell refreshCellWithTitle:arr[indexPath.row] info:self.calculate AndType:5];
            }
        }else {
            [cell refreshCellWithTitle:arr[indexPath.row] info:@"" AndType:0];
        }
    }else {
        if (indexPath.section == 0) {
            [cell refreshCellWithTitle:arr[indexPath.row] info:@"" AndType:0];
        }else if (indexPath.section == 1) {
            if (indexPath.row == 0) {
                [cell refreshCellWithTitle:arr[indexPath.row] info:self.mvoeZero AndType:1];
            }else if (indexPath.row == 1) {
                [cell refreshCellWithTitle:arr[indexPath.row] info:self.priorityPaymentMethod AndType:8];
            }else if (indexPath.row == 2){
                [cell refreshCellWithTitle:arr[indexPath.row] info:self.rounded AndType:2];
            }else if (indexPath.row == 3){
                [cell refreshCellWithTitle:arr[indexPath.row] info:self.negativeInventory AndType:3];
            }else if (indexPath.row == 4){
                [cell refreshCellWithTitle:arr[indexPath.row] info:self.negativeSales AndType:4];
            }else if (indexPath.row == 5){
                [cell refreshCellWithTitle:arr[indexPath.row] info:self.calculate AndType:5];
            }else if (indexPath.row == 6){
                [cell refreshCellWithTitle:arr[indexPath.row] info:self.individualDiscount AndType:7];
            }
        }else if (indexPath.section == 2) {
            if ([SAValueManger shareInStance].userInfo.userType == 1) {
                [cell refreshCellWithTitle:arr[indexPath.row] info:self.payment AndType:6];
            }else {
                [cell refreshCellWithTitle:arr[indexPath.row] info:@"" AndType:0];
            }
        }else {
            [cell refreshCellWithTitle:arr[indexPath.row] info:@"" AndType:0];
        }
    }
    
    
    cell.eraseBlock = ^{
        [weakSelf showMoreView];
    };
    cell.payBlock = ^(NSString * _Nonnull typeStr) {
        [weakSelf payView:typeStr];
    };
    cell.negativeInventoryBlock = ^(NSString * _Nonnull tag) {
        weakSelf.systemSettingsCheckAPI.value = tag;
        weakSelf.systemSettingsCheckAPI.settingsId = self.negativeInventoryDic[@"settingsId"];
        weakSelf.systemSettingsCheckAPI.parentId = @"";
        [weakSelf.systemSettingsCheckAPI sendRequestToServerWithActivityViewAndMask:POST];
    };
    cell.negativeSalesBlock = ^(NSString * _Nonnull tag) {
        weakSelf.systemSettingsCheckAPI.value = tag;
        weakSelf.systemSettingsCheckAPI.settingsId = self.negativeSalesDic[@"settingsId"];
        weakSelf.systemSettingsCheckAPI.parentId = @"";
        [weakSelf.systemSettingsCheckAPI sendRequestToServerWithActivityViewAndMask:POST];
    };
    cell.roundedBlock = ^(NSString * _Nonnull tag) {
        weakSelf.systemSettingsCheckAPI.value = tag;
        weakSelf.systemSettingsCheckAPI.settingsId = self.roundedDic[@"settingsId"];
        weakSelf.systemSettingsCheckAPI.parentId = @"";
        [weakSelf.systemSettingsCheckAPI sendRequestToServerWithActivityViewAndMask:POST];
    };
    cell.calculateBlock = ^(NSString * _Nonnull tag) {
        weakSelf.systemSettingsCheckAPI.value = tag;
        weakSelf.systemSettingsCheckAPI.settingsId = self.calculateDic[@"settingsId"];
        weakSelf.systemSettingsCheckAPI.parentId = @"";
        [weakSelf.systemSettingsCheckAPI sendRequestToServerWithActivityViewAndMask:POST];
    };
    cell.individualDiscountBlock = ^(NSString * _Nonnull tag) {
        weakSelf.systemSettingsCheckAPI.value = tag;
        weakSelf.systemSettingsCheckAPI.settingsId = self.individualDiscountDic[@"settingsId"];
        weakSelf.systemSettingsCheckAPI.parentId = @"";
        [weakSelf.systemSettingsCheckAPI sendRequestToServerWithActivityViewAndMask:POST];
    };
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    WeakSelf
    NSMutableArray *menuList = [SAValueManger shareInStance].userInfo.menuList;
    NSString *openPayment = [NSString stringWithFormat:@"%@",menuList[9][@"perms"][@"openPayment"]];
    if ([SAValueManger shareInStance].userInfo.userType != 1) {
        if (indexPath.section == 1) {
            if (![openPayment isEqualToString:@"1"] && [SAValueManger shareInStance].userInfo.isMarketingOpen.integerValue == 1) {
                if (indexPath.row == 0) {
                    SAOpenPayVC *pushVC = [SAOpenPayVC new];
                    [self.navigationController pushViewController:pushVC animated:YES];
                }else if (indexPath.row == 1) {
                    SAAboutUsVC *pushVC = [SAAboutUsVC new];
                    [self.navigationController pushViewController:pushVC animated:YES];
                }
            }else {
                if (indexPath.row == 0) {
                    SAAboutUsVC *pushVC = [SAAboutUsVC new];
                    [self.navigationController pushViewController:pushVC animated:YES];
                }
            }
        }
    }else {
        if (indexPath.section == 0) {
            if (indexPath.row == 0) {
                SAMemberSetVC *pushVC = [SAMemberSetVC new];
                [self.navigationController pushViewController:pushVC animated:YES];
            }else if (indexPath.row == 1) {
                SAMemberIntegralVC *pushVC = [SAMemberIntegralVC new];
                [self.navigationController pushViewController:pushVC animated:YES];
            }else if (indexPath.row == 2) {
                SADiscountSetVC *pushVC = [SADiscountSetVC new];
                [self.navigationController pushViewController:pushVC animated:YES];
            }
        }else if (indexPath.section == 1) {
            
        }else if (indexPath.section == 2) {
            if  ([SAValueManger shareInStance].userInfo.userType == 1) {
                SAPaymentVC *pushVC = [SAPaymentVC new];
                [self.navigationController pushViewController:pushVC animated:YES];
                pushVC.refreshBlock = ^{
                    [weakSelf loadData];
                };
            }else {
                SAAboutUsVC *pushVC = [SAAboutUsVC new];
                [self.navigationController pushViewController:pushVC animated:YES];
            }
        }else if (indexPath.section == 3) {
            
            if (![openPayment isEqualToString:@"1"]) {
                if (indexPath.row == 0) {
                    SAOpenPayVC *pushVC = [SAOpenPayVC new];
                    [self.navigationController pushViewController:pushVC animated:YES];
                }else if (indexPath.row == 1) {
                    SAAboutUsVC *pushVC = [SAAboutUsVC new];
                    [self.navigationController pushViewController:pushVC animated:YES];
                }
            }else {
                if (indexPath.row == 0) {
                    SAAboutUsVC *pushVC = [SAAboutUsVC new];
                    [self.navigationController pushViewController:pushVC animated:YES];
                }
            }
        }
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return kScaleNum(43);
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = kBgColor;
    UILabel *textLab = [[UILabel alloc] init];
    textLab.textColor = kBlackColor;
    textLab.font = kFont(16);
    
    if ([SAValueManger shareInStance].userInfo.userType == 1) {
        if (section == 0) {
            textLab.text = @"会员";
        }else if (section == 1) {
            textLab.text = @"销售/入库";
        }else if (section == 2) {
            textLab.text = @"调配货";
        }else {
            textLab.text = @"";
        }
    }else {
        if (section == 0) {
            textLab.text = @"销售/入库";
        }else {
            textLab.text = @"";
        }
    }
    
    [view addSubview:textLab];
    [textLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.centerY.mas_equalTo(0);
    }];
    return view;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [[UIView alloc] initWithFrame:CGRectZero];
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == self.dataMarr.count - 1) {
        return kScaleNum(8);
    }
    return kScaleNum(43);
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    if (section == self.dataMarr.count - 1) {
        return kScaleNum(60);
    }
    return 0.01;
}

#pragma mark - event
-(void)clickedAccountBtn {
    SAMyAccountVC *pushVC = [[SAMyAccountVC alloc] init];
    [self.navigationController pushViewController:pushVC animated:YES];
}

-(void)clickedPrintBtn {
    CATransition *transition = [CATransition animation];
    transition.duration = 0.3f;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionPush;
    transition.subtype = kCATransitionFromRight;
    transition.delegate = self;
    [self.view.layer addAnimation:transition forKey:nil];
    [self.view addSubview:self.printSettingsVC.view];
}

-(void)clickedPaperSetBtn {
    NSString *systemBillManagement = [NSString stringWithFormat:@"%@",[SAValueManger shareInStance].userInfo. menuList[9][@"perms"][@"systemBillManagement"]];
    if (![systemBillManagement isEqualToString:@"0"]) {
        [Prompt popPromptViewWithMsg:@"您没有票据设置权限,请联系店长添加" duration:2];
        return;
    }
    
    SAPaperSetVC *pushVC = [[SAPaperSetVC alloc] init];
    [self.navigationController pushViewController:pushVC animated:YES];
}

-(void)clickedEraseBtn:(UIButton *)sender {
    if (sender.tag == 1) {
        self.eraseAngleBtn.selected = YES;
        self.systemSettingsCheckAPI.value = @"1";
    }else if (sender.tag == 2) {
        self.erasePointsBtn.selected = YES;
        self.systemSettingsCheckAPI.value = @"2";
    }else {
        self.noEraseBtn.selected = YES;
        self.systemSettingsCheckAPI.value = @"0";
    }
    self.systemSettingsCheckAPI.settingsId = self.mvoeZeroDic[@"settingsId"];
    self.systemSettingsCheckAPI.parentId = self.mvoeZeroDic[@"parentId"];
    [self.systemSettingsCheckAPI sendRequestToServerWithActivityViewAndMask:POST];
    self.moreView.hidden = YES;
}

-(void)showMoreView {
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:1];
    if ([SAValueManger shareInStance].userInfo.userType != 1) {
        indexPath = [NSIndexPath indexPathForRow:1 inSection:0];
    }
    SAMySelfCell* cell = [self.tableView cellForRowAtIndexPath:indexPath];
    UIView *keyWindow = [UIApplication sharedApplication].keyWindow;
    CGRect rect = [keyWindow convertRect:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height) fromView:cell];
    self.imageV.y = rect.origin.y;
    
    self.noEraseBtn.selected = NO;
    self.eraseAngleBtn.selected = NO;
    self.erasePointsBtn.selected = NO;
    if ([self.mvoeZero isEqualToString:@"1"]) {
        self.eraseAngleBtn.selected = YES;
    }else if ([self.mvoeZero isEqualToString:@"2"]) {
        self.erasePointsBtn.selected = YES;
    }else {
        self.noEraseBtn.selected = YES;
    }
    self.moreView.hidden = NO;
}

-(void)payView:(NSString *) payType{
    
    NSString *type = @"1";
    if ([payType isEqualToString:@"现金"]) {
        type = @"1";
    }else if ([payType isEqualToString:@"刷卡"]) {
        type = @"2";
    }else if ([payType isEqualToString:@"汇款"]) {
        type = @"3";
    }else if ([payType isEqualToString:@"微信"]) {
        type = @"4";
    }else if ([payType isEqualToString:@"支付宝"]) {
        type = @"5";
    }else if ([payType isEqualToString:@"余额"]) {
        type = @"6";
    }else if ([payType isEqualToString:@"扫码"]) {
        type = @"7";
    }
    self.systemSettingsCheckAPI.value = type;
    self.systemSettingsCheckAPI.settingsId = self.priorityPaymentMethodDic[@"settingsId"];
    self.systemSettingsCheckAPI.parentId = self.priorityPaymentMethodDic[@"parentId"];
    [self.systemSettingsCheckAPI sendRequestToServerWithActivityViewAndMask:POST];
}

-(void)removeView {
    self.moreView.hidden = YES;
}

-(void)loadData {
    [self.systemSettingsListAPI sendRequestToServerWithActivityViewAndMask:GET];
}

#pragma mark - initUI
-(void)initUI {
    [self setTitle:@"全局设置"];
    [self setBgImage:nil];
    self.negativeInventory = @"0";
    self.negativeSales = @"0";
    self.mvoeZero = @"0";
    self.view.backgroundColor = kBgColor;
    
    [self.view addSubview:self.tableView];
    
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScaleNum(122))];
    headerView.backgroundColor = [UIColor whiteColor];
    NSArray *arr = @[@"我的账号", @"打印机连接", @"票据设置"];
    for (int i = 0; i < arr.count; i++) {
        UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(kScaleNum(20), i * kScaleNum(40.5), kScaleNum(150), kScaleNum(40))];
        titleLab.text = arr[i];
        titleLab.textColor = kBlackColor;
        titleLab.font = kFont(15);
        [headerView addSubview:titleLab];
        
        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, i * kScaleNum(40.5) +  kScaleNum(40), kScreenWidth, kScaleNum(0.5))];
        line.backgroundColor = kBgColor;
        [headerView addSubview:line];
        
        UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth - kScaleNum(30), kScaleNum(12.5) + i * kScaleNum(40.5), kScaleNum(8), kScaleNum(15))];
        imageV.image = [UIImage imageNamed:@"Sale_rightArrow"];
        [headerView addSubview:imageV];
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(0, i * kScaleNum(40.5), kScreenWidth, kScaleNum(40));
        [headerView addSubview:btn];
        if (i == 0) {
            [btn addTarget:self action:@selector(clickedAccountBtn) forControlEvents:UIControlEventTouchUpInside];
        }else if (i == 1) {
            [btn addTarget:self action:@selector(clickedPrintBtn) forControlEvents:UIControlEventTouchUpInside];
        }else {
            [btn addTarget:self action:@selector(clickedPaperSetBtn) forControlEvents:UIControlEventTouchUpInside];
        }
    }
    [self.view addSubview:self.tableView];
    self.tableView.tableHeaderView = headerView;
    
    self.printSettingsVC = [SAPrintSettingsVC new];
    
    UIWindow *window =  [UIApplication sharedApplication].keyWindow;
    [window addSubview:self.moreView];
    
    [self.systemSettingsListAPI sendRequestToServerWithActivityViewAndMask:GET];
}

#pragma mark - lazy
-(UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kScaleNum(StatusHeight + 1), kScreenWidth, kScreenHeight - kScaleNum(StatusHeight + 1) - SafeFooterHeight) style:UITableViewStyleGrouped];
        _tableView.backgroundColor = kBgColor;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.showsHorizontalScrollIndicator = NO;
        if (@available(iOS 11.0, *)) {
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
        _tableView.bounces = NO;
        _tableView.estimatedRowHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        [_tableView registerClass:[SAMySelfCell class] forCellReuseIdentifier:@"SAMySelfCell"];
    }
    return _tableView;
}

-(NSMutableArray *)dataMarr {
    if (!_dataMarr) {
        _dataMarr = [NSMutableArray array];
        NSArray *arr = @[@"会员级别设置", @"会员积分设置", @"折扣设置"];
        NSArray *arr2 = @[@"应收抹零", @"首选付款方式", @"四舍五入(销售结算价格四舍五入)", @"负库存入库(向供货商退货)", @"负库存销售(无库存销售)", @"余额消费计算提成",@"散客是否享受折扣"];
        NSArray *arr3 = @[@"结算方式(调配货时默认结算方式)"];
        NSArray *arr4 = @[@"关于我们"];
        
        NSMutableArray *menuList = [SAValueManger shareInStance].userInfo.menuList;
        NSString *openPayment = [NSString stringWithFormat:@"%@",menuList[9][@"perms"][@"openPayment"]];
        if (![openPayment isEqualToString:@"1"] && [SAValueManger shareInStance].userInfo.isMarketingOpen.integerValue == 1) {
            arr4 = @[@"开通支付", @"关于我们"];
        }
        
        if ([SAValueManger shareInStance].userInfo.userType == 1) {
            [_dataMarr addObject:arr];
            [_dataMarr addObject:arr2];
            [_dataMarr addObject:arr3];
            [_dataMarr addObject:arr4];
        }else {
            [_dataMarr addObject:arr2];
            [_dataMarr addObject:arr4];
        }
    }
    return _dataMarr;
}

-(UIView *)moreView {
    if (!_moreView) {
        _moreView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
        _moreView.backgroundColor = kColor(0, 0, 0, 0.3);
        _moreView.hidden = YES;
        _moreView.userInteractionEnabled = YES;
        
        UIImageView *imageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"shop_moreView2"]];
        self.imageV = imageV;
        imageV.frame = SARectMake(183, StatusHeight + 320, 172, 143);
        [_moreView addSubview:imageV];
        imageV.userInteractionEnabled = YES;
        [imageV addSubview:self.noEraseLab];
        [imageV addSubview:self.noEraseBtn];
        [imageV addSubview:self.noEraseLine];
        [imageV addSubview:self.eraseAngleLab];
        [imageV addSubview:self.eraseAngleBtn];
        [imageV addSubview:self.eraseAngleLine];
        [imageV addSubview:self.erasePointsLab];
        [imageV addSubview:self.erasePointsBtn];
        [imageV addSubview:self.erasePointsLine];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeView)];
        [_moreView addGestureRecognizer:tap];
    }
    return _moreView;
}

-(UILabel *)noEraseLab {
    if (!_noEraseLab) {
        _noEraseLab = [[UILabel alloc] initWithFrame:SARectMake(83, 12, 80, 43)];
        _noEraseLab.text = @"(如88.88)";
        _noEraseLab.textColor = kLightgGrayColor;
        _noEraseLab.font = kFont(15);
    }
    return _noEraseLab;
}

-(UIButton *)noEraseBtn {
    if (!_noEraseBtn) {
        _noEraseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _noEraseBtn.frame = SARectMake(0, 12, 172, 43);
        _noEraseBtn.tag = 0;
        [_noEraseBtn setTitle:@"不抹零" forState:UIControlStateNormal];
        _noEraseBtn.titleLabel.font = kFont(15);
        [_noEraseBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
        [_noEraseBtn setTitleColor:kBuleColor forState:UIControlStateSelected];
        _noEraseBtn.titleEdgeInsets = UIEdgeInsetsMake(0, kScaleNum(-60), 0, 0);
        [_noEraseBtn addTarget:self action:@selector(clickedEraseBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _noEraseBtn;
}

-(UIView *)noEraseLine {
    if (!_noEraseLine) {
        _noEraseLine = [[UIView alloc] initWithFrame:SARectMake(10, 55, 152, 1)];
        _noEraseLine.backgroundColor = kLineColor;
    }
    return _noEraseLine;
}

-(UILabel *)eraseAngleLab {
    if (!_eraseAngleLab) {
        _eraseAngleLab = [[UILabel alloc] initWithFrame:SARectMake(83, 56, 80, 43)];
        _eraseAngleLab.text = @"(如88)";
        _eraseAngleLab.textColor = kLightgGrayColor;
        _eraseAngleLab.font = kFont(15);
    }
    return _eraseAngleLab;
}

-(UIButton *)eraseAngleBtn {
    if (!_eraseAngleBtn) {
        _eraseAngleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _eraseAngleBtn.frame = SARectMake(0, 56, 172, 43);
        _eraseAngleBtn.tag = 1;
        [_eraseAngleBtn setTitle:@"抹掉角" forState:UIControlStateNormal];
        _eraseAngleBtn.titleLabel.font = kFont(15);
        [_eraseAngleBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
        [_eraseAngleBtn setTitleColor:kBuleColor forState:UIControlStateSelected];
        _eraseAngleBtn.titleEdgeInsets = UIEdgeInsetsMake(0, kScaleNum(-60), 0, 0);
        [_eraseAngleBtn addTarget:self action:@selector(clickedEraseBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _eraseAngleBtn;
}

-(UIView *)eraseAngleLine {
    if (!_eraseAngleLine) {
        _eraseAngleLine = [[UIView alloc] initWithFrame:SARectMake(10, 99, 152, 1)];
        _eraseAngleLine.backgroundColor = kLineColor;
    }
    return _eraseAngleLine;
}

-(UILabel *)erasePointsLab {
    if (!_erasePointsLab) {
        _erasePointsLab = [[UILabel alloc] initWithFrame:SARectMake(83, 100, 80, 43)];
        _erasePointsLab.text = @"(如88.8)";
        _erasePointsLab.textColor = kLightgGrayColor;
        _erasePointsLab.font = kFont(15);
    }
    return _erasePointsLab;
}

-(UIButton *)erasePointsBtn {
    if (!_erasePointsBtn) {
        _erasePointsBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _erasePointsBtn.frame = SARectMake(0, 100, 172, 43);
        [_erasePointsBtn setTitle:@"抹掉分" forState:UIControlStateNormal];
        _erasePointsBtn.titleLabel.font = kFont(15);
        _erasePointsBtn.tag = 2;
        [_erasePointsBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
        [_erasePointsBtn setTitleColor:kBuleColor forState:UIControlStateSelected];
        _erasePointsBtn.titleEdgeInsets = UIEdgeInsetsMake(0, kScaleNum(-60), 0, 0);
        [_erasePointsBtn addTarget:self action:@selector(clickedEraseBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _erasePointsBtn;
}

-(SASystemSettingsListAPI *)systemSettingsListAPI {
    if (!_systemSettingsListAPI) {
        _systemSettingsListAPI = [SASystemSettingsListAPI apiWithDelegate:self];
    }
    return _systemSettingsListAPI;
}

-(SASystemSettingsCheckAPI *)systemSettingsCheckAPI {
    if (!_systemSettingsCheckAPI) {
        _systemSettingsCheckAPI = [SASystemSettingsCheckAPI apiWithDelegate:self];
    }
    return _systemSettingsCheckAPI;
}

@end
